package com.dunshan.order.controller;


import com.alibaba.fastjson.JSON;
import com.dunshan.order.config.AppContext;
import com.dunshan.order.pojo.User;
import com.dunshan.order.mapper.UserMapper;
import com.dunshan.order.service.UserService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;


/**
 * @author dunshan
 * @program: dunshan-pef
 * @description: 订单服务index
 * @date 2021-10-02 14:47:29
 */
@Log4j2
@RestController
public class OrderController {

    @Autowired
    UserService userService;


    @GetMapping("/order/user/{id}")
    public String orderInfo(@PathVariable(value = "id") Integer id) {
        String result = null;
        String traceId = AppContext.getContext().getFlag();
//        System.out.println("====traceId =========\n" + traceId);
        if ("7DGroup".equals(traceId)) {
            HashMap<String, Object> map = userService.selectHashMap();
            List<User> users = userService.selectList();
            result = traceId + "->-order-" + id + "-->" + JSON.toJSONString(users) + "- redis- " + JSON.toJSONString(map);
            log.info("order : 我是压测流量");
            return result;
        }
        log.info("order我是正常流量。。。。。。");
        HashMap<String, Object> map = userService.selectHashMap();
        result = " --> 我是没有头信息-> dunshan-order" + JSON.toJSONString(map);
        return result;
    }

}
